<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .center{
            text-align: center;
        }
    </style>
</head>
<body>
<!--{{include './header.html'}}-->

<h1 style="text-align: center;color: brown">登陆</h1>
<div style="width: 500px;margin: 0 auto;margin-top: 200px; ">
<label>账号</label>&nbsp;&nbsp;<input id="z"  style="width: 400px;height: 30px" placeholder="账号">
<div style="height: 50px"></div>
<label>密码</label>&nbsp;&nbsp;<input id="m"   style="width: 400px;height: 30px" placeholder="密码"><br>
    <a id="re" style="color:green;font-size: 20px;margin-top: 50px;display: block">登陆</a>
    <a  href="/register" style="color:green;font-size: 20px;margin-top: 50px;display: block">注册</a >
</div>
<script type="text/javascript" src="/node_modules/jquery/dist/jquery.js"></script>
<script>
    var z=document.getElementById("z")
    var m=document.getElementById("m")

    var re=document.getElementById("re")

    re.onclick=function(){

        name=z.value
        password=m.value

        var hc={
            name:name,
            password:password
        }

        $.ajax({
            type: "POST",
            url: "/login",
            data: hc,
            dataType:"json",
            success: function(data){

                if(data.code_err==1){
                    console.log(data)
                    var token =JSON.stringify(data.token)
                    localStorage.setItem('token',token)
                    window.location.href="/";

                }

                if(data.code_err==0){
                    alert('账号或者密码错误');
                }

            }
        });

    }


</script>
</body>
</html>